package com.mytecblog.framework.service.impl;

import com.mytecblog.framework.dao.IBaseDao;
import com.mytecblog.framework.dao.IDao;
import com.mytecblog.framework.entity.MetaObject;
import com.mytecblog.framework.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**基本服务实现类
 * @author yg.huang
 * @version v1.0
 *          DATE  2016/10/31
 */
@Service
public class BaseServiceImpl<T extends MetaObject,D extends IBaseDao<T>>  implements IBaseService<T,D>{

    /**
     * 根据泛型自动注入的Dao
     */
    @Autowired
    protected D dao;

    public void save(T entity) {
        Date date=new Date();
        if(entity.getCreateTime()==null){
            entity.setCreateTime(date);
        }
        entity.setUpdateTime(date);
        dao.save(entity);
    }

    public void delete(T entity) {
        dao.delete(entity);
    }

    public void delete(long id) {

        dao.delete(id);
    }

    public T get(long id) {
        return dao.get(id);
    }

    public List<T> findByProperty(String propertyName, Object value) {
        return dao.findByProperty(propertyName,value);
    }

    public List<T> findAll(String orderBy) {
        return dao.findAll(orderBy);
    }

    public T findUniqueByProperty(String propertyName, Object value) {
        return dao.findUniqueByProperty(propertyName,value);
    }


}
